package org.jactao.remote.netty.codec;

import io.netty.handler.codec.ByteToMessageDecoder;
import org.jactao.common.LException;
import org.jactao.remote.netty.codec.marshalling.MarshallingCodecFactory;
import org.jactao.serialization.kryo.KryoSerializer;

/**
 * Created by fanzetao on 2018/4/9.
 */
public class DecoderFactory {

    public static ByteToMessageDecoder get(String serialize) {
        if(serialize == null)
            throw new LException("no found  " + serialize + " serializer support ");

        switch (serialize) {
            case "kryo":
                return new NettyDecoder(10 * 1024).serializer(new KryoSerializer());
            case "marshaller":
                return MarshallingCodecFactory.buildMarshallingDecoder();
            default:
                throw new LException("no found  " + serialize + " serializer support ");
        }
    }
}
